<?php
session_start();
$reqlevel="ADM";
include 	('../../users2k/getlevel.php');
/*
$action="<span class='proc'>BonTa: importar créditos</span>";
include 	('../../users2k/loguser.php');
*/
require_once('../../adodb/adodb.inc.php');
require_once('../../Connections/forms2.php');
require_once('../../procfunc.php');
require_once('../../datediff.php');
require_once('../../tools/Financial/amortizacion-SF1.php');
require_once('../../genid.php');

if($id) {
$monto=getvalor(2264);
$tasa=getvalor(4685);
$tasa_bon=getvalor(4768);
$plazo=getvalor(4697);
$frec=getvalor(4698);
$gracia=getvalor(4699);
if($frec==0) $frec=12;
$fechaini=explode('-',getvalor(4702));
}
$ppa=12/$frec;
$cantcuot=$plazo/$frec;
// function Amortization($principal,$payments,$interestrate,$paymentsperyear='12',$grace,$expand=FALSE) {
$paymentschedule = Amortization($monto, $cantcuot, $tasa,$ppa,$gracia,TRUE);
// calculo array de fechas
// int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] )

$fecha_pago=array();
$fecha_liq=array();
$num_days=array();
	for($i=0;$i<=$cantcuot+1;$i++){
	$month=$fechaini[1]+($frec*$i);
	$year=$fechaini[0];
	$fecha_pago[$i]=date('Y-m-d',mktime(0,0,0,$month,1,$year));
	$fecha_liq[$i]=date('Y-m-d',mktime(0,0,0,$month+1,1,$year));
	}

	for($i=0;$i<=$cantcuot;$i++){
	$date1=strtotime($fecha_pago[$i]);
	$date2=strtotime($fecha_pago[$i+1]);
	$num_days[$i]=DateDiff ('d', $date1,$date2);
	//echo $fecha_pago[$i+1].' - '.$fecha_pago[$i].'='.DateDiff ('d', $date1,$date2).'<br />';
	}
	
$tasaB=6/100;

?>
 <table border="1" cellpadding="2" class='amortable' cellspacing="0">
 <tr>
 <th>Fecha
 </th>
 <th>Nro</th>
 <th>Total</th>
 <th>Capital</th>
 <th>Intereses</th>
 <th>Acumulado</th>
 <th>Acumulado interes</th>
 <th>Remanente</th>
 <th>Fecha Liq Bon</th>
 <th>Dias</th>
 <th>Bonif</th>
 </tr>
<?php
//-- me preparo para insertar el plan de cuotas.

 foreach($paymentschedule as $payment) {
  $capital+=$payment['principalpayment'];
  print("
  <tr>
  <td>".$fecha_pago[$payment['payment']]."</td>
  <td>".$payment['payment']."</td>
  <td>$".number_format($payment['amount'],2)."</td>
  <td>$".number_format($payment['principalpayment'],2)."</td>
  <td>$".number_format($payment['interestpayment'],2)."</td>
  <td>$".number_format($payment['totalpaid'],2)."</td>
  <td>$".number_format($payment['totalinterest'],2)."</td>
  <td>$".number_format($payment['remaining'],2)."</td>
  <td>".$fecha_liq[$payment['payment']]."</td>
  <td>".$num_days[$payment['payment']]."</td>
  <td>$ $payment[remaining]*$tasaB*".$num_days[$payment[payment]]."/365 =".number_format(round($payment['remaining']*$tasaB*$num_days[$payment['payment']]/365,2),2)."</td>
  </tr>
 ");
 }
?>
 </table>
<?="<b>$monto - ".round($capital,14)." = ".($monto-$capital)."</b>";
?><style>
.amortable{ font-family:"Trebuchet MS", Arial; font-size:.7em;
 
}
</style>